<script type="text/javascript" src="../media/system/js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="../media/system/js/jQuery.vietvang.validate.js"></script>
  <script type="text/javascript">
    $(document).ready(function(){
      $('#adminForm').validate({
      });
    });
</script>
<form ID="adminForm" action="index.php?option=com_mail_group"  method="post" enctype="multipart/form-data" name="adminForm" class="form-validate">   
      <fieldset class="adminform">
      <table border="0" class="adminformlist" style="width: 425px;padding-top: 0px;">
         <tr>
            <td></td>
            <td style="color: red;font-size:"><span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;text-align: left;">※印は入力必須項目です。</span></td>
            <td style="visibility: hidden;"><label style="text-align: right;font-size: 1.091em;padding-right:5px;">ID</label></td>
            <td style="visibility: hidden;"><label class="label_questionare_id"><?php echo HelperBG::getIDAuto('magr','MAGR_CODE');?></label></td>
         </tr>
         <tr>
            <td><label id="jform_state-lbl" for="jform_state" class="hasTip" title="" style="text-align: right;font-size: 1.091em;padding-right:5px;" >グループ名<span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;">※</span></label></td>
            <td>
              <input vvName="fullname" data_required="true" id="g_name" name="g_name" class="inputbox big" />
              <span name="msg_error"></span>
            </td>
            
         </tr>
         <tr>
            <td><label style="text-align: right;font-size: 1.091em;padding-right:5px;">ユーザタイプ</label> </td>      
            <td>
              <select id="type" name="type" class="inputbox medium">               
               <option value="0" >本部ユーザ</option>               
               <option value="3" >センターユーザ</option>
               <option value="4" >クラブユーザ</option>
               <option value="1" >指導員</option>
               <option value="2" >外部ユーザ</option>
            </select>
          </td>
         </tr>
        </table>
   </fieldset>

   <div id='external' class="h_form">
      <p>外部ユーザ</p>
      <p><label> メールアドレス登録&nbsp;&nbsp;&nbsp;</label><input name="filecsv" type="file" accept=".csv"/></p>
   </div>
   <div id="relationship" class="h_form">
      <table>
        <tr>    
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;">B&G関係ユーザ</td>
        </tr>
        <tr>
            <td style="width: 150px;"></td>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;">地区</td>
            <td>
                <select id="area" class="inputbox medium">
                   <option value='all'>全て</option>
                   <?php 
                        foreach($this->getModel()->getArea() as $area){
                            echo "<option value='$area->AREA_CODE'>$area->AREA_NAME</option>";
                        }
                   ?>
                </select>
            </td>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;">都道府県</td>
            <td>
                <select id="pref" class="inputbox medium">
                   <option value='all'>全て</option>
                   <?php 
                        foreach($this->getModel()->getPrefs() as $pref){
                            echo "<option value='$pref->PREF_CODE'>$pref->PREF_NAME</option>";
                        }
                   ?>
                </select>
            </td>
            <td style="text-align: right;font-size: 1.091em;padding-right:5px;">センタークラブ</td>
            <td>
                <input id="keyword" type="text" class="inputbox medium"/>
            </td>
        </tr>
      </table><br />
      <p><input id="search" type="button" value="検索" style="width: 60px;"/></p>
      <table class="adminlist" id="result">
		<thead>
			<tr>
                <th  width="1%">
					<input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />
				</th>
				<th class="left">ユーザ名 </th>
				<th class="left">メールアドレス</th>
			</tr>
		</thead>
	
		<tbody >

		</tbody>
	</table>
   
   <input type="hidden" name="task" value=""/>
   <input type="hidden" name="action" value="new" />
</form>
<script>
	Joomla.submitbutton = function(task){
    if (task == 'cancel' ){
      window.location.href = "index.php?option=com_mail_group";
    }else {
      Joomla.submitform(task, document.getElementById('adminForm'));
    }
  }
    
    jq('#area').change(function(event){
        jq('#pref').load('index.php?option=com_mail_group&task=ajax_get_pref&tmpl=component&area_code='+jq('#area').val());
        //alert (jq('#pref').val());'
    });
    
    jq('#type').change(function(event){      
        jq('.h_form').hide();

        if (jq('#type').val() == 2){
            jq('#external').show();
        } else {
            jq('#relationship').show();
        }
    });
    
    jq(function(){
        jq('.h_form').hide();
        
        if (jq('#type').val() == 2){
            jq('#external').show();
        } else {
            jq('#relationship').show();
        }
    });
    
    jq('#search').click(function(){
        jq.ajax({
          url: 'index.php?option=com_mail_group&task=ajax_search&tmpl=component'
            +'&keyword='+encodeURI(jq('#keyword').val())
            +'&type='+jq('#type').val()
            +'&area='+jq('#area').val()
            +'&pref='+jq('#pref').val(),
          context: document.body
        }).done(function(data ) {
          jq('#result').html(data);
        });

    });   
</script>


